package com.yulebaby.callsenter.utils;

import android.support.v7.util.DiffUtil;

import com.yulebaby.callsenter.bean.multiplebean.MultipleCustomerBean;

import java.util.List;

/**
 * Author: Zhangbo
 * Time: 2016/12/27
 */
public class DiffUtils extends DiffUtil.Callback {
    private List<MultipleCustomerBean> mOldDatas, mNewDatas;//看名字

    public DiffUtils(List<MultipleCustomerBean> mOldDatas, List<MultipleCustomerBean> mNewDatas) {
        this.mOldDatas = mOldDatas;
        this.mNewDatas = mNewDatas;
    }

    @Override
    public int getOldListSize() {
        return mOldDatas != null ? mOldDatas.size() : 0;
    }

    @Override
    public int getNewListSize() {
        return mNewDatas != null ? mNewDatas.size() : 0;
    }


    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        MultipleCustomerBean beanOld = mOldDatas.get(oldItemPosition);
        MultipleCustomerBean beanNew = mNewDatas.get(newItemPosition);
        if (beanOld.getItemType() == MultipleCustomerBean.CUSTOMERITEM && beanNew.getItemType() == MultipleCustomerBean.CUSTOMERITEM) {
            return beanOld.getCustomerBean().getCustomer_id().equals(beanNew.getCustomerBean().getCustomer_id());
        } else if (beanOld.getItemType() == MultipleCustomerBean.TIME && beanNew.getItemType() == MultipleCustomerBean.TIME) {
            return beanOld.getTime().equals(beanNew.getTime());
        }
        return false;
    }


    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        MultipleCustomerBean beanOld = mOldDatas.get(oldItemPosition);
        MultipleCustomerBean beanNew = mNewDatas.get(newItemPosition);
        if (beanOld.getItemType() == MultipleCustomerBean.CUSTOMERITEM && beanNew.getItemType() == MultipleCustomerBean.CUSTOMERITEM) {
            return beanOld.getCustomerBean().getCustomer_id().equals(beanNew.getCustomerBean().getCustomer_id());
        } else if (beanOld.getItemType() == MultipleCustomerBean.TIME && beanNew.getItemType() == MultipleCustomerBean.TIME) {
            return beanOld.getTime().equals(beanNew.getTime());
        }
        return true;
    }
}
